package com.taomu.app.zongchouhuli.moudle.mine.contract.impl;

import android.util.Log;


import com.taomu.app.zongchouhuli.http.api.HttpObserver;
import com.taomu.app.zongchouhuli.http.api.Request;
import com.taomu.app.zongchouhuli.http.res.ResSelectBankEntity;
import com.taomu.app.zongchouhuli.moudle.mine.contract.UserSelectBankContract;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.schedulers.Schedulers;

public class UserSelectBankPresenter implements UserSelectBankContract.Presenter {

    private UserSelectBankContract.View mContractView;

    private CompositeDisposable disposable;

    public UserSelectBankPresenter(UserSelectBankContract.View mContractView){
        this.mContractView = mContractView;
        this.disposable = new CompositeDisposable();
    }

    @Override
    public void getSelectBanks() {
        Request.getIntence().getSelectBank()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new HttpObserver<ResSelectBankEntity>(mContractView,disposable,true) {
                    @Override
                    public void onNext(ResSelectBankEntity resProductEntities) {
                        Log.d("wqdqwdwqdwqdwq","onNext:"+resProductEntities.getData().size());
                        if(mContractView != null){
                            mContractView.setBanks(resProductEntities);
                        }
                    }
                });
    }

    @Override
    public void onStart() {

    }

    @Override
    public void onDetch() {
        mContractView = null;
        if(disposable != null){
            disposable.dispose();
            disposable = null;
        }
    }
}
